<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">用户管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">总代理基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                	<div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">accountId：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="accountId" value="" readonly>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">名称：</label>
                                         <div class="col-lg-8">
                                         	 <input type="text" id="nickname" value="" readonly>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">头像：</label>
                                         <div class="col-lg-8">
                                             <p><img id="image" src="" width="50px"></p>
                                         </div>
                                     </div>
                                     <div class="form-group" id="provinceDiv">
                                         <label class="col-lg-2 clo-md-2 control-label">配送省份：</label>
                                         <div class="col-lg-8">
                                             <select class="form-control" id="provinceList" multiple="multiple" onchange="provinceChange()">
                                             </select>
                                         </div>
                                     </div>  
                                     <div class="form-group" id="shiquDiv">
                                     </div> 
                                     <div class="form-group" id="diquDiv">
                                     </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="cashRed_modify()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	$(function(){
		var accountId = "${accountId}";
		var baseURL = "${webPath}/partner/detail";
	  	var json_package = {
	       "head": {},
	       "body": {
	       	"accountId": accountId
	       }
	   	}
		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	      if (typeof result == 'string') result = JSON.parse(result);
	      if (result.body.result == '1') {
	          alert(result.body.description)
	      } else {
	      	var account = result.body.account;
	      	$("#accountId").val(account.accountId);
	      	$("#nickname").val(account.nickname);
	      	$("#image").attr('src',account.image); 
	      	
	      	baseURL = "${webPath}/partner/listOfProvince";
		    json_package = {
		        "head": {},
		        "body": {
		        	"accountId":accountId
		        }
		    }
		    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
		        if (typeof result == 'string') result = JSON.parse(result);
		        console.log(result);
		        if (result.body.result == '1') {
		            $("#provinceDiv").hide();
		            $("#provinceList").empty();
		        } else {
		        	$("#provinceList").empty();
		        	var list = result.body.list;
		        	var str = "";
		        	if(list.length<=0){
		        		return
		        	}
		        	for(var i=0;i<list.length;i++){
		        		if(list[i].isHave == 1){
		        			str += '<option value="'+list[i].provinceId+'" selected>'+list[i].name+'</option>';
		        		}else{
		        			str += '<option value="'+list[i].provinceId+'" >'+list[i].name+'</option>';
		        		}
		        	}
		        	$("#provinceList").append(str);
		        }
		    })
	      }
	  	})
	});
	
	function provinceChange(){
		var objSelect = document.getElementById("provinceList");
   	 	for(var i=0;i<objSelect.options.length;i++) {
		 	var option = objSelect.options[i];
  		 	var provinceId = objSelect.options[i].value;
   		 	if(option.selected == true ){
    			
 				$("#shiquDiv").empty();
 				
 				var accountId = "${accountId}";
   			 	var baseURL = "${webPath}/partner/listOfCity";
    			var json_package = {
   			        "head": {},
   			        "body": {
   			        	"accountId":accountId,
   			        	"provinceId":provinceId
   			        }
   			    }
   			    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
   			        if (typeof result == 'string') result = JSON.parse(result);
   			        console.log(result);
   			     	if (result.body.result == '0') {
	 		        	var list = result.body.list;
	 		        	var str = "";
	 		        	if(list.length<=0){
	 		        		return
	 		        	}
	 		        	
	 		        	str += '<div class="form-group" id="cityDiv">';
 		        		str += '	<label class="col-lg-2 clo-md-2 control-label">配送市：</label>';
 		        		str += '	<div class="col-lg-8">';
 		        		str += '		<select class="form-control" id="cityList'+provinceId+'" name="cityList" multiple="multiple" onchange="cityChange('+provinceId+')">';
 		        		
	 		        	for(var i=0;i<list.length;i++){
	 		        		if(list[i].isHave == 1){
	 		        			str += '		<option value="'+list[i].cityId+'" selected>'+list[i].name+'</option>';
	 		        		}else{
	 		        			str += '		<option value="'+list[i].cityId+'" >'+list[i].name+'</option>';
	 		        		}
	 		        	}
	 		        	
	 		        	str += '		</select>';
 		        		str += '	</div>';
 		        		str += '</div>';
	 		        	$("#shiquDiv").append(str);
	 		        }
   			    })
   		 	}
   		}
    }
	
	function cityChange(provinceId){
		var objSelect = document.getElementById("cityList"+provinceId);
   	 	for(var i=0;i<objSelect.options.length;i++) {
		 	var option = objSelect.options[i];
  		 	var cityId = objSelect.options[i].value;
   		 	if(option.selected == true ){
    			
 				$("#diquDiv").empty();
 				
 				var accountId = "${accountId}";
   			 	var baseURL = "${webPath}/partner/listOfDistrict";
    			var json_package = {
   			        "head": {},
   			        "body": {
   			        	"accountId":accountId,
   			        	"cityId":cityId
   			        }
   			    }
   			    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
   			        if (typeof result == 'string') result = JSON.parse(result);
   			        console.log(result);
   			     	if (result.body.result == '0') {
	 		        	var list = result.body.list;
	 		        	var str = "";
	 		        	if(list.length<=0){
	 		        		return
	 		        	}
	 		        	
	 		        	str += '<div class="form-group" id="districtDiv">';
 		        		str += '	<label class="col-lg-2 clo-md-2 control-label">配送区：</label>';
 		        		str += '	<div class="col-lg-8">';
 		        		str += '		<select class="form-control" id="districtList" name="districtList" multiple="multiple" onchange="cityChange()">';
 		        		
	 		        	for(var i=0;i<list.length;i++){
	 		        		
	 		        		if(list[i].isHave == 1){
	 		        			str += '		<option value="'+list[i].districtId+'" selected>'+list[i].name+'</option>';
	 		        		}else{
	 		        			str += '		<option value="'+list[i].districtId+'" >'+list[i].name+'</option>';
	 		        		}
	 		        	}
	 		        	
	 		        	str += '		</select>';
 		        		str += '	</div>';
 		        		str += '</div>';
	 		        	$("#diquDiv").append(str);
	 		        }
   			    })
   		 	}
   		}
    }
	
	$(function () {
        $('#cancel').click(function () {
            var baseURL = "${webPath}/toPartner";
            window.open(baseURL);
        })
    });
</script>
</body>
</html>